<template>
	<!-- 门票管理 -->
	<div>
		<MyNavbar title="门票管理">
			<div slot="right">
				<u-button type="text" text="添加" @click="onClickAdd()"></u-button>
			</div>
		</MyNavbar>
		
		<u-list
			@scrolltolower="scrolltolower"
		>
			<u-list-item
				v-for="(item, index) in list"
				:key="index"
				class="base-box"
			>
				<div @tap="onClickEdit(item)">
					<u-cell
						:border="false"
						clickable
						:title="item.title"
						
					>
					</u-cell>
					<div>
						<div><span >门票价格：</span><span>{{item.price}}</span></div>
						<div><span >库存：</span><span>{{item.stock}}</span></div>
						<div><span >城市：</span><span>{{item.city}}</span></div>
						<div><span >时间：</span><span>{{item.beginTime}} 至 {{item.endTime}}</span></div>
					</div>
				</div>
			</u-list-item>
			
			<u-loadmore :status="loadStatus" />
		</u-list>
		
		
	</div>
</template>

<script>
	export default {
		props: {
			
		},
		data() {
			return {
				
				pageSet: {
					page: 1,
					pageSize: 20
				},
				// loadmore  loading / nomore
				loadStatus: 'loadmore',
				// 分页列表数据
				pageData: {},
			}
		},
		computed: {
			list(){
				let {pageData} = this;
				if (pageData) {
					let list = [];
					console.log("pageData", pageData);
					for (let key in pageData) {
						console.log("key-", key);
						console.log("pageData", pageData);
						list.push(...pageData[key]);
					}
					return list;
				}
				return [];
			},
		},
		onShow() {
			this.onRefresh();
		},
		onLoad() {
			
		},
		mounted(){
			
		},
		onPullDownRefresh() {
			this.onRefresh();
		},
		methods: {
			// 刷新
			onRefresh(){
				this.pageData = {};
				this.queryList(1, this.pageSet.pageSize);
			},
			// 查询列表
			queryList(page, pageSize){
				let form = {
					page: page,
					pageSize: pageSize,
				};
				this.loadStatus = 'loading';
				this.$api.goods.query(form).then(({data})=>{
					uni.stopPullDownRefresh();
					this.pageSet.page = page;
					
					let records = data.records;
					if (records && records.length > 0) {
						this.$set(this.pageData, page + "", records);
						
						this.loadStatus = data.total >= this.pageSet.pageSize ? 'loadmore' : 'nomore';
					} else {
						this.loadStatus = 'nomore';
					}
				}).catch(e=>{
					uni.stopPullDownRefresh();
					this.loadStatus = 'nomore';
				});
			},
			// 点击添加按钮
			onClickAdd(){
				uni.navigateTo({
					url: '/pagesAdmin/admin/goods/edit?operType=add'
				})
			},
			// 点击编辑
			onClickEdit(item){
				uni.navigateTo({
					url: '/pagesAdmin/admin/goods/edit?operType=edit&uid=' + item.uid
				})
			},
			// 滚动到底部
			scrolltolower(){
				console.log('滚动到底部');
				let {loadStatus} = this;
				if (loadStatus === 'loadmore') {
					let page = this.pageSet.page + 1;
					this.queryList(page, this.pageSet.pageSize);
				}
			},
		}
	}
	
</script>

<style>
</style>
